/**
 * @author gao
 * @date 2025/7/17 14:53
 */

class Singleton {
    // 创建唯一实例
    // 此处的instance属于static成员，创建时机，就是在类加载的时候
    private static Singleton instance = new Singleton();
    public static Singleton getInstance() {
        return instance;
    }

    private Singleton() {
    }
}

public class Demo1 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2);// s1和s2指向同一对象
    }
}